package com.htgd.gardenexpo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.dao.GeConSportMapper;
import com.htgd.gardenexpo.entity.GeConSport;
import com.htgd.gardenexpo.page.SportQuery;
import com.htgd.gardenexpo.service.GeBaseDictService;
import com.htgd.gardenexpo.service.GeConSportService;
import com.htgd.gardenexpo.service.WxUserCollectService;
import com.htgd.gardenexpo.utils.TokenUtil;
import com.htgd.gardenexpo.vo.GeConSportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 运动科普 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-08-24
 */
@Service
public class GeConSportServiceImpl extends ServiceImpl<GeConSportMapper, GeConSport> implements GeConSportService {

    @Autowired
    private GeConSportMapper geConSportMapper;

    @Autowired
    private GeBaseDictService geBaseDictService;

    @Autowired
    private WxUserCollectService wxUserCollectService;



    @Override
    public PageInfo<GeConSportVO> pageList(SportQuery sportQuery, HttpServletRequest request) {
        PageHelper.startPage(sportQuery.getPageNum(), sportQuery.getPageSize());
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        List<GeConSportVO> list= geConSportMapper.pageList(sportQuery);
        for (GeConSportVO geConSportVO : list) {
            if(geConSportVO.getStatus()!=null){
                geConSportVO.setStatusText(geBaseDictService.getStatusText(String.valueOf(geConSportVO.getStatus())));
            }
            if(geConSportVO.getIsTop()!=null){
                geConSportVO.setIsTopText(geBaseDictService.getTopText(String.valueOf(geConSportVO.getIsTop())));
            }
            Boolean collect = wxUserCollectService.isLike(openId, geConSportVO.getId().toString(),"sport");
            if (collect) {
                geConSportVO.setIsLike(true);
            }else{
                geConSportVO.setIsLike(false);
            }
        }
        return new PageInfo<>(list);
    }

}
